﻿var _this_pager;
function Fypager(div,fuc) {
    this.currPage = 1;
    this.totalPage = 1;
    this.pageNum = 10;
    this.div = $("#" + div);
    this.query = fuc ;
    _this_pager = this;
}
Fypager.prototype.nextPage= function() {
    if (this.currPage < this.totalPage)
        this.currPage++;
    this.query();
}
Fypager.prototype.previewPage = function() {
    if (this.currPage > 1)
        this.currPage--;
    this.query();
}
Fypager.prototype.goPage = function(page) {
    if (!isNaN(page)) {
        if (page >= this.totalPage) {
            this.currPage = this.totalPage;
        } else if (page < 1) {
            this.currPage = 1;
        } else {
            this.currPage = page;
        }
        this.query();
    }
}
Fypager.prototype.changeSize = function (size) {
    if (size != this.pageNum) {
        this.pageNum = size;
        this.query();
    }
}
/*Fypager.prototype.showPager = function (totalPage, totalNum, pageCount) {
    this.totalPage = totalPage;
    this.div.html('<span>显示条数:</span>' + '<select id="pageNum" onchange="_btnChange(this[selectedIndex].value)"><option value="10">10</option><option value="20">20</option><option value="30">30</option><option value="50">50</option></select>' + '<span id="spCount">' + "|共" + totalNum + "条" + '</span> <a href="javascript:_previewPage();">上一页</a> <span id="spPager">' + this.currPage + "/" + this.totalPage + '</span> <a href="javascript:_nextPage();">下一页</a> | 第<input type="text" id="_pageIndex" style="border:1px solid #ccc;width:22px;">页 <input type="button" value="GO" onclick="_goPage();" class="btncolor"> &nbsp; &nbsp;');
    var SelectObj = document.getElementById("pageNum");
    for (var i = 0; i < SelectObj.options.length; i++) {
        if (SelectObj.options[i].value == pageCount) {
            SelectObj.options[i].selected = true;
            break;
        }
    }
}*/
Fypager.prototype.showPager = function (totalPage, totalNum, pageCount) {
    this.totalPage = totalPage;
    this.div.html('<span>显示条数:</span>' + '<select id="pageNum" onchange="_btnChange(this[selectedIndex].value)"><option value="100">100</option><option value="200">200</option><option value="300">300</option><option value="500">500</option></select>' + '<span id="spCount">' + "|共" + totalNum + "条" + '</span> <a href="javascript:_previewPage();">上一页</a> <span id="spPager">' + this.currPage + "/" + this.totalPage + '</span> <a href="javascript:_nextPage();">下一页</a> | 第<input type="text" id="_pageIndex" style="border:1px solid #ccc;width:22px;">页 <input type="button" value="GO" onclick="_goPage();" class="btncolor"> &nbsp; &nbsp;');
    var SelectObj = document.getElementById("pageNum");
    for (var i = 0; i < SelectObj.options.length; i++) {
        if (SelectObj.options[i].value == pageCount) {
            SelectObj.options[i].selected = true;
            break;
        }
    }
}

function _previewPage() {
    _this_pager.previewPage();
}

function _nextPage() {
    _this_pager.nextPage();
}

function _goPage() {
    _this_pager.goPage($("#_pageIndex").val());
}
function _btnChange(value) {
    _this_pager.changeSize(value);
}